package cn.buk.qms.config;

import cn.buk.alert.service.AlertService;
import cn.buk.alert.service.AlertServiceImpl;
import org.apache.activemq.spring.ActiveMQConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.core.JmsTemplate;

/**
 *
 * @author yfdai
 */
@Configuration
public class JmsConfiguration {

    @Value("${url_activemq_broker}")
    private String brokerUrl;

    @Value("${jms_destination_qinfo}")
    private String jmsDestinationQinfo;

    @Bean
    public ActiveMQConnectionFactory amqConnectionFactory() {
        ActiveMQConnectionFactory amqConnectionFactory = new ActiveMQConnectionFactory();
        amqConnectionFactory.setBrokerURL(brokerUrl);
        return amqConnectionFactory;
    }


    @Bean
    public JmsTemplate qinfoJmsTemplate() {
        JmsTemplate jmsTemplate = new JmsTemplate();
        jmsTemplate.setConnectionFactory(amqConnectionFactory());
        jmsTemplate.setDefaultDestinationName(jmsDestinationQinfo);
        return jmsTemplate;
    }

    @Bean
    public AlertService createAlertService() {
        return new AlertServiceImpl(qinfoJmsTemplate());
    }


}
